package com.enjoyireland.hiking;

import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RatingBar;
import android.widget.TextView;

public class WalkDetails extends Fragment implements Constants {
	private WalkDBHelper	_walkContent;
	private SQLiteDatabase 	_walkDB;
	private View			_root;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
	        Bundle savedInstanceState) {
		return _root = inflater.inflate(R.layout.detail_tab, container, false);
	}
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		/* configure */
		setRetainInstance(true);
		setHasOptionsMenu(true);
		
		// get details for walk with specified _id
		Uri _id = getActivity().getIntent().getData();
		_walkContent = new WalkDBHelper(getActivity());
		_walkDB = _walkContent.getReadableDatabase();
		String[] details = _walkContent.getWalkDetails(_walkDB,_id);
		// update database with viewed walk status
		_walkContent.viewedWalk(_walkDB, _id);
		_walkDB.close();
		
		((TextView)_root.findViewById(R.id.detailName)).setText(details[COL_NAME_INDEX]);
		((TextView)_root.findViewById(R.id.detailLength)).setText(details[COL_LEN_INDEX]+" km");
		((TextView)_root.findViewById(R.id.detailGR)).setText(details[COL_GRID_INDEX]);
		((TextView)_root.findViewById(R.id.detailDesc)).setText(details[COL_DESC_INDEX]);
		((TextView)_root.findViewById(R.id.detailEquip)).setText(details[COL_EQUIP_INDEX]);
		((TextView)_root.findViewById(R.id.detailTerrain)).setText(details[COL_TERRAIN_INDEX]);
		((TextView)_root.findViewById(R.id.detailCo)).setText(details[COL_CO_INDEX]);
		((RatingBar)_root.findViewById(R.id.walkDiff)).setNumStars(Integer.valueOf(details[COL_DIFF_INDEX]));
	}
}
